package com.mes.inventory.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.mes.common.service.BasicService;
import com.mes.inventory.dao.iface.IInvCheckDao;
import com.mes.inventory.dao.iface.IInvCheckDetailDao;
import com.mes.inventory.dao.iface.IInvIODetailDao;
import com.mes.inventory.dao.iface.IInvlnfoDao;
import com.mes.inventory.domain.InvCheck;
import com.mes.inventory.domain.InvCheckDetail;
import com.mes.inventory.domain.InvInfo;
@Service
public class InvCheckDetailService extends BasicService<InvCheckDetail>{
	
	@Autowired
	private IInvCheckDetailDao invCheckDetailDao;
	
	@Autowired
	private IInvCheckDao invCheckDao;
	
	@Autowired
	private IInvlnfoDao invlnfoDao;
	//生成盘点单明细
	@DataResolver
	public void  createCheckDetails(Map<String,Object> parameter) throws Exception{
		String warehouseUid = (String)parameter.get("warehouseUid");
		String invCheckUid = (String)parameter.get("invCheckUid");
		List<InvInfo> invInfos = invlnfoDao.findByProperty("warehouseUid", warehouseUid);
		List<InvCheckDetail> invCheckDetails = new ArrayList<InvCheckDetail>();
		int i = 1;
		for (InvInfo invInfo : invInfos) {
			InvCheckDetail invCheckDetail = new InvCheckDetail();
			invCheckDetail.setInvCheckUid(invCheckUid);
			invCheckDetail.setWarehouseUid(invInfo.getWarehouseUid());
			invCheckDetail.setWarebinUid(invInfo.getWarebinUid());
			invCheckDetail.setMaterialUid(invInfo.getMaterialUid());
			invCheckDetail.setAccountedQty(invInfo.getInvQty());
			invCheckDetail.setUom(invInfo.getUom());
			invCheckDetail.setActualQty(invInfo.getInvQty());
			invCheckDetail.setSeq(i);
			i++;
			invCheckDetails.add(invCheckDetail);
		}
		invCheckDetailDao.add(invCheckDetails);
	}
}
